<?php

namespace app\models;

use Yii;
use app\models\Person;
use app\models\Park;

/**
 * This is the model class for table "shbb_company".
 *
 * @property integer $id
 * @property string $code
 * @property string $name
 * @property string $addr
 * @property string $introduction
 * @property integer $pricipal_id
 * @property string $tel
 * @property string $email
 * @property string $comment
 * @property string $qualification_image
 *
 * @property Person $pricipal
 * @property Park[] $shbbParks
 */
class Company extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shbb_company';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'pricipal_id'], 'integer'],
            [['introduction'], 'string'],
            [['code', 'name', 'addr', 'tel', 'email', 'comment', 'qualification_image'], 'string', 'max' => 255],
            [['code'], 'unique'],
            ['email','email'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'code' => '公司编号',
            'name' => '公司名',
            'addr' => '公司地址',
            'introduction' => '公司介绍',
            'pricipal_id' => '负责人',
            'tel' => '联系电话',
            'email' => '电子邮箱',
            'comment' => '备注',
            'qualification_image' => '资质照片',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPricipal()
    {
        return $this->hasOne(Person::className(), ['id' => 'pricipal_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getParks()
    {
        return $this->hasMany(Park::className(), ['company_id' => 'id']);
    }
}
